package com.woniu.gf.pawn.management.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.gf.pawn.comm.core.domain.Management;
import com.woniu.gf.pawn.comm.core.domain.Permission;
import com.woniu.gf.pawn.comm.core.domain.Role;
import com.woniu.gf.pawn.management.dao.RoleMapper;
import com.woniu.gf.pawn.management.param.SelectManagementByRoleIdParam;
import com.woniu.gf.pawn.management.param.SelectPermissionByRoleIdParam;
import com.woniu.gf.pawn.management.param.SelectRoleParam;
import com.woniu.gf.pawn.management.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2020-10-13
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public List<Management> selectManagementByRoleId(SelectManagementByRoleIdParam selectManagementByRoleIdParam) {
        List<Management> managements=roleMapper.selectManagementByRoleId(selectManagementByRoleIdParam.getRoleId(),selectManagementByRoleIdParam.getManagementName());
        return managements;
    }

    @Override
    public List<Management> selectManagementNotRoleByRoleId(SelectManagementByRoleIdParam selectManagementByRoleIdParam) {
        List<Management> managements=roleMapper.selectManagementNotRoleByRoleId(selectManagementByRoleIdParam.getRoleId(),selectManagementByRoleIdParam.getManagementName());
        return managements;
    }

    @Override
    public void deleteManagementRoleByRoleId(int roleId) {
        roleMapper.deleteManagementRoleByRoleId(roleId);

    }

    @Override
    public IPage<Role> selectPageRole(SelectRoleParam selectRoleParam) {
        Page<Role> page=new Page<>(selectRoleParam.getPageIndex(),selectRoleParam.getPageSize());
        IPage<Role> roleIPage=roleMapper.selectPageRole(page,selectRoleParam.getRoleName());
        return roleIPage;
    }

    @Override
    public void deleteRolePermissionByRoleId(int roleId) {
        roleMapper.deleteRolePermissionByRoleId(roleId);
    }

    @Override
    public List<Permission> selectPermissionByRoleId(SelectPermissionByRoleIdParam selectPermissionByRoleIdParam) {
        List<Permission> permissions=roleMapper.selectPermissionByRoleId(selectPermissionByRoleIdParam.getRoleId(),
                selectPermissionByRoleIdParam.getPermissionCategoryId(),selectPermissionByRoleIdParam.getPermissionName());
        return permissions;
    }

    @Override
    public List<Permission> selectPermissionNotByRoleId(SelectPermissionByRoleIdParam selectPermissionByRoleIdParam) {
        List<Permission> permissions=roleMapper.selectPermissionNotByRoleId(selectPermissionByRoleIdParam.getRoleId(),
                selectPermissionByRoleIdParam.getPermissionCategoryId(),selectPermissionByRoleIdParam.getPermissionName());
        return permissions;
    }

}
